﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

namespace H2.NET.Web.Pages
{
    public partial class PHKF : TaskPage
    {
        #region 属性 Public
        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }
        #endregion

        #region 事件 Page_Load(页面加载)
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;
                //InitDropDownList();

                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    VD.Checked = true;
                }
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                {
                    InitDropDownList();
                    SetColor();
                }
                #endregion

                #region 审批环节
                if(!TaskAPI.IsInitiate)
                {
                    #region 加载数据并显示 
                    HKF_Finance finance = (HKF_Finance.process == TaskAPI.Process & HKF_Finance.incident == TaskAPI.Incident).ListFirst<HKF_Finance>();
                    if (finance != null)
                    {
                        ApplicationNo.Text                  = finance.ApplicationNo;
                        Actions.SelectedValue = finance.Actions;
                        SetDropDownListValue(DrpPriority, finance.DrpPriority);
                        VD.Checked                          = finance.VD_Checked == "1"; 
                        SA.Checked                          = finance.SA_Checked == "1";
                        SA2.Checked                         = finance.SA2_Checked == "1";
                        SA3.Checked                         = finance.SA3_Checked == "1";
                        SA4.Checked                         = finance.SA4_Checked == "1";

                        IS_CO_Area.Text                     = finance.IS_CO_Area;
                        IS_Cost_Element.Text                = finance.IS_Cost_Element;
                        Vaild_From.Text                     = finance.Vaild_From;
                        Vaild_To.Text                       = finance.Vaild_To;
                        RE_Cost_Element.Text                = finance.RE_Cost_Element;
                        RE_CO_Area.Text                     = finance.RE_CO_Area;
                        Name.Text                           = finance.Name;
                        Description.Text                    = finance.Description;       
                        SetDropDownListValue(Cost_Element_Category, finance.Cost_Element_Category);

                        Element_Group_CO_Area.Text          = finance.Element_Group_CO_Area;
                        Cost_Element_Group.Text             = finance.Cost_Element_Group;
                        Copy_Cost_Element_Group.Text        = finance.Copy_Cost_Element_Group;
                        Chart_Accounts.Text                 = finance.Chart_Accounts;
                        Element_Group_Name.Text             = finance.Element_Group_Name;
                        SetDropDownListValue(Cost_Element_1, finance.Cost_Element_1);
                        SetDropDownListValue(Cost_Element_2, finance.Cost_Element_2);
                        SetDropDownListValue(Cost_Element_3, finance.Cost_Element_3);
                        SetDropDownListValue(Cost_Element_4, finance.Cost_Element_4);

                        IS_Center_CO_Area.Text              = finance.IS_Center_CO_Area;
                        IS_Cost_Center.Text                 = finance.IS_Cost_Center;
                        IS_Center_From.Text                 = finance.IS_Center_From;
                        IS_Center_To.Text                   = finance.IS_Center_To;
                        RE_Cost_Center.Text                 = finance.RE_Cost_Center;
                        Cost_Center_CO_Area.Text            = finance.Cost_Center_CO_Area;
                        Cost_Center_Name.Text               = finance.Cost_Center_Name;
                        Cost_Center_Description.Text        = finance.Cost_Center_Description;
                        Person_Responsible.Text             = finance.Person_Responsible;
                        SetDropDownListValue(Cost_Center_Category, finance.Cost_Center_Category);

                        Hierarchy_Area.Text                 = finance.Hierarchy_Area;
                        Company_Code.SelectedValue            = finance.Company_Code;

                        SetDropDownListValue(Functional_Area, finance.Functional_Area);
                        SetDropDownListValue(Currency, finance.Currency);
                        SetDropDownListValue(Profit_Center, finance.Profit_Center);
                        Record_Quantity.Checked             = finance.Record_Quantity == "1";
                        Actual_Revenues.Checked             = finance.Actual_Revenues == "1";
                        Plan_Revenues.Checked               = finance.Plan_Revenues == "1";

                        Center_Group_CO_Area.Text           = finance.Center_Group_CO_Area;
                        Cost_Center_Group.Text              = finance.Cost_Center_Group;
                        SetDropDownListValue(Copy_Cost_Center_Group, finance.Copy_Cost_Center_Group);
                        Copy_CO_Area.Text                   = finance.Copy_CO_Area;
                        Center_Group_Name.Text              = finance.Center_Group_Name;
                        SetDropDownListValue(Center_Group_Name_1, finance.Center_Group_Name_1);
                        SetDropDownListValue(Center_Group_Name_2, finance.Center_Group_Name_2);
                        SetDropDownListValue(Center_Group_Name_3, finance.Center_Group_Name_3);
                        SetDropDownListValue(Center_Group_Name_4, finance.Center_Group_Name_4);
                        SetDropDownListValue(Center_Group_Name_5, finance.Center_Group_Name_5);
                        

                        IS_GL_Account.Text                  = finance.IS_GL_Account;
                        IS_1718.Checked                     = finance.IS_1718 == "1";
                        IS_4118.Checked                     = finance.IS_4118 == "1";
                        IS_4119.Checked                     = finance.IS_4119 == "1";
                        IS_8856.Checked                     = finance.IS_8856 == "1";
                        IS_4127.Checked                     = finance.IS_4127 == "1";
                        RE_GL_Account.Text                  = finance.RE_GL_Account;
                        RE_1718.Checked                     = finance.RE_1718 == "1";
                        RE_4118.Checked                     = finance.RE_4118 == "1";
                        RE_4119.Checked                     = finance.RE_4119 == "1";
                        RE_8856.Checked                     = finance.RE_8856 == "1";
                        RE_4127.Checked                     = finance.RE_4127 == "1";
                        SetDropDownListValue(Account_Currency, finance.Account_Currency);
                        Only_Balance.Checked                = finance.Only_Balance == "1";
                        Tax_Category.SelectedValue            = finance.Tax_Category;
                        Without_Tax.Checked                 = finance.Without_Tax == "1";
                        Recon_Account.SelectedValue           = finance.Recon_Account;
                        Account_No.Text                     = finance.Account_No;
                        Open_Item.Checked                   = finance.Open_Item == "1";
                        Line_Item.Checked                   = finance.Line_Item == "1";
                        Sort_key.Text                       = finance.Sort_key;
                        Accounting_Clerk.SelectedValue        = finance.Accounting_Clerk;
                        SetDropDownListValue(Field_Status_Group, finance.Field_Status_Group);
                        Post_Automatically_Only.Checked = finance.Post_Automatically_Only == "1";
                        SetDropDownListValue(Planning_Level, finance.Planning_Level);
                        Relevant_To_Cash.Checked            = finance.Relevant_To_Cash == "1";
                        Yes_No.SelectedValue                  = finance.Yes_No;
                        SetDropDownListValue(GL_Cost_Element_Category, finance.GL_Cost_Element_Category);
                        Financial_Statement.Text            = finance.Financial_Statement;

                        SetDropDownListValue(DMO_DrpPriority, finance.DMO_DrpPriority);
                      
                    }
                    #endregion

                    #region 审批项初始化
                    switch(TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                      
                    }
                    #endregion
                }
                #endregion

                SetDefaultValue();

                #region 设置控件禁启用
                //bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, VD, SA, SA2, SA3, Actions, DrpPriority, SA4, Financial_Statement, IS_Cost_Element, Vaild_From, Vaild_To, RE_Cost_Element, RE_CO_Area, Name, Description, Cost_Element_Category, Cost_Element_Group, Copy_Cost_Element_Group, Element_Group_Name, Cost_Element_1, Cost_Element_2, Cost_Element_3, Cost_Element_4, IS_Cost_Center, IS_Center_From, IS_Center_To, RE_Cost_Center, Cost_Center_CO_Area, Cost_Center_Name, Cost_Center_Description, Person_Responsible, Cost_Center_Category, Hierarchy_Area, Company_Code, Functional_Area, Currency, Profit_Center, Cost_Center_Group, Copy_Cost_Center_Group, Copy_CO_Area, Center_Group_Name, Center_Group_Name_1, Center_Group_Name_2, Center_Group_Name_3, Center_Group_Name_4, Center_Group_Name_5, IS_GL_Account, IS_1718, IS_4118, IS_4119, IS_8856, IS_4127, RE_GL_Account, RE_1718, RE_4118, RE_4119, RE_8856, RE_4127, Account_Currency, Only_Balance, Tax_Category, Without_Tax, Recon_Account, Account_No, Open_Item, Accounting_Clerk, Field_Status_Group, Post_Automatically_Only, Planning_Level, Relevant_To_Cash, Yes_No, GL_Cost_Element_Category);
                //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);


                //if (TaskAPI.Step == "DMO Approve")
                //{
                //    SetForeColor(Color.Blue, DMO_DrpPriority_L);
                //}
                //SetVisible(Actions.SelectedValue != "1", P1, P2, P3);
                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                //tb.Enabled = true;
                                //item = tb.SelectedItem.Text;
                                //value = tb.SelectedValue.ToString();
                                //tb.Items.Clear();
                                //tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                //tb.Enabled = true;
                                //item = tb.SelectedItem.Text;
                                //value = tb.SelectedValue.ToString();
                                //tb.Items.Clear();
                                //tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                //tb.Enabled = true;
                                //item = tb.SelectedItem.Text;
                                //value = tb.SelectedValue.ToString();
                                //tb.Items.Clear();
                                //tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                    foreach (Control cr in P_SA3.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                //tb.Enabled = true;
                                //item = tb.SelectedItem.Text;
                                //value = tb.SelectedValue.ToString();
                                //tb.Items.Clear();
                                //tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA3.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                    foreach (Control cr in P_SA4.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                //tb.Enabled = true;
                                //item = tb.SelectedItem.Text;
                                //value = tb.SelectedValue.ToString();
                                //tb.Items.Clear();
                                //tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA4.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                }

                #endregion

                
            }
        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if ((TaskAPI.IsBeginStep || TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Check" || TaskAPI.Step == "DMO Approve") && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }
                    
                    TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text)
                                    + " / " + ApplicationNo.Text + (VD.Checked ? " / Cost Element " : "") + (SA.Checked ? " / Cost Element Group " : "") + (SA2.Checked ? " / Cost Center " : "") + (SA3.Checked ? " / Cost Center Group " : "") + (SA4.Checked ? " / GL Account " : "");

                    //TaskAPI["finance_Type"] = VD.Checked && VD_finance_Type.SelectedValue == "内部(Internal)" ? "Internal" : "";
                    TaskAPI["Actions"]        = Actions.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == Actions.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    //m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.dr2EmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    //if(oc != null)
                    //{
                    //    TaskAPI["R_Manager_Approve2"] = oc.WinID;
                    //}

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

                
                
                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        HKF_Finance finance = new HKF_Finance();
                        if ((HKF_Finance.process == TaskAPI.Process & HKF_Finance.incident == TaskAPI.Incident & HKF_Finance.userName == UserAPI.UserName).Count<HKF_Finance>() > 0)
                        {
                            finance = (HKF_Finance.process == TaskAPI.Process & HKF_Finance.incident == TaskAPI.Incident & HKF_Finance.userName == UserAPI.UserName).ListFirst<HKF_Finance>();
                        }
                        else
                        {
                            finance.Process       = TaskAPI.Process;
                            finance.Incident      = TaskAPI.Incident;
                            finance.UserName      = UserAPI.UserName;
                            finance.UserFullName  = UserAPI.UserFullName;
                            finance.ApplicationNo = ApplicationNo.Text;
                            finance.Time          = System.DateTime.Now;
                            finance.Status        = 0;
                            finance.Department    = UserAPI.Department;
                        }

                        finance.Actions            = Actions.SelectedValue;
                        finance.DrpPriority = DrpPriority.SelectedValue;
                        //finance.Actions           = Actions.SelectedItem.Text;

                        finance.VD_Checked        = VD.Checked ? "1" : "0";
                        finance.SA_Checked        = SA.Checked ? "1" : "0";
                        finance.SA2_Checked       = SA2.Checked ? "1" : "0";
                        finance.SA3_Checked       = SA3.Checked ? "1" : "0";
                        finance.SA4_Checked       = SA4.Checked ? "1" : "0";

                        #region VD
                        if (VD.Checked)
                        {
                            finance.IS_CO_Area          = IS_CO_Area.Text;
                            finance.IS_Cost_Element     = IS_Cost_Element.Text;
                            finance.Vaild_From          = Vaild_From.Text;
                            finance.Vaild_To            = Vaild_To.Text;
                            finance.RE_Cost_Element     = RE_Cost_Element.Text;
                            finance.RE_CO_Area          = RE_CO_Area.Text;
                            finance.Name                = Name.Text;
                            finance.Description         = Description.Text;
                            finance.Cost_Element_Category = Cost_Element_Category.SelectedValue;

                        }
                        #endregion

                        #region SA
                        if (SA.Checked)
                        {
                            finance.Element_Group_CO_Area = Element_Group_CO_Area.Text;
                            finance.Cost_Element_Group = Cost_Element_Group.Text;
                            finance.Copy_Cost_Element_Group = Copy_Cost_Element_Group.Text;
                            finance.Chart_Accounts = Chart_Accounts.Text;
                            finance.Element_Group_Name = Element_Group_Name.Text;
                            finance.Cost_Element_1 = Cost_Element_1.SelectedValue;
                            finance.Cost_Element_2 = Cost_Element_2.SelectedValue;
                            finance.Cost_Element_3 = Cost_Element_3.SelectedValue;
                            finance.Cost_Element_4 = Cost_Element_4.SelectedValue;

                        }
                        #endregion

                        #region SA2
                        if (SA2.Checked)
                        {
                            finance.IS_Center_CO_Area   = IS_Center_CO_Area.Text;
                            finance.IS_Cost_Center      = IS_Cost_Center.Text;
                            finance.IS_Center_From      = IS_Center_From.Text;
                            finance.IS_Center_To        = IS_Center_To.Text;
                            finance.RE_Cost_Center      = RE_Cost_Center.Text;
                            finance.Cost_Center_CO_Area = Cost_Center_CO_Area.Text;
                            finance.Cost_Center_Name    = Cost_Center_Name.Text;
                            finance.Cost_Center_Description = Cost_Center_Description.Text;
                            finance.Person_Responsible   = Person_Responsible.Text;
                            finance.Cost_Center_Category = Cost_Center_Category.SelectedValue;
                            finance.Hierarchy_Area       = Hierarchy_Area.Text;
                            finance.Company_Code         = Company_Code.SelectedValue;
                            finance.Functional_Area = Functional_Area.SelectedValue;
                            finance.Currency            = Currency.SelectedValue;
                            
                            finance.Profit_Center       = Profit_Center.SelectedValue;
                            finance.Record_Quantity     = Record_Quantity.Checked ? "1" : "0";
                            finance.Actual_Revenues     = Actual_Revenues.Checked ? "1" : "0";
                            finance.Plan_Revenues       = Plan_Revenues.Checked ? "1" : "0";

                        }
                        #endregion

                        #region SA3
                        if (SA3.Checked)
                        {
                            finance.Center_Group_CO_Area    = Center_Group_CO_Area.Text;
                            finance.Cost_Center_Group       = Cost_Center_Group.Text;
                            finance.Copy_Cost_Center_Group  = Copy_Cost_Center_Group.SelectedValue;
                            finance.Copy_CO_Area            = Copy_CO_Area.Text;
                            finance.Center_Group_Name       = Center_Group_Name.Text;
                            finance.Center_Group_Name_1     = Center_Group_Name_1.SelectedValue;
                            finance.Center_Group_Name_2     = Center_Group_Name_2.SelectedValue;
                            finance.Center_Group_Name_3     = Center_Group_Name_3.SelectedValue;
                            finance.Center_Group_Name_4     = Center_Group_Name_4.SelectedValue;
                            finance.Center_Group_Name_5     = Center_Group_Name_5.SelectedValue;

                        }
                        #endregion

                        #region SA4
                        if (SA4.Checked)
                        {
                            finance.IS_GL_Account = IS_GL_Account.Text;
                            finance.IS_1718                 = IS_1718.Checked ? "1" : "0";
                            finance.IS_4118                 = IS_4118.Checked ? "1" : "0";
                            finance.IS_4119                 = IS_4119.Checked ? "1" : "0";
                            finance.IS_8856                 = IS_8856.Checked ? "1" : "0";
                            finance.IS_4127                 = IS_4127.Checked ? "1" : "0";
                            finance.RE_GL_Account           = RE_GL_Account.Text;
                            finance.RE_1718                 = RE_1718.Checked ? "1" : "0";
                            finance.RE_4118                 = RE_4118.Checked ? "1" : "0";
                            finance.RE_4119                 = RE_4119.Checked ? "1" : "0";
                            finance.RE_8856                 = RE_8856.Checked ? "1" : "0";
                            finance.RE_4127                 = RE_4127.Checked ? "1" : "0";
                            finance.Account_Currency        = Account_Currency.SelectedValue;
                            
                            finance.Only_Balance            = Only_Balance.Checked ? "1" : "0";
                            finance.Tax_Category            = Tax_Category.SelectedValue;
                            finance.Without_Tax             = Without_Tax.Checked ? "1" : "0";
                            finance.Recon_Account           = Recon_Account.SelectedValue;
                            finance.Account_No              = Account_No.Text;
                            finance.Open_Item               = Open_Item.Checked ? "1" : "0";
                            finance.Line_Item               = Line_Item.Checked ? "1" : "0";
                            finance.Sort_key                = Sort_key.Text;
                            finance.Accounting_Clerk        = Accounting_Clerk.SelectedValue;
                            finance.Field_Status_Group      = Field_Status_Group.SelectedValue;
                            finance.Post_Automatically_Only = Post_Automatically_Only.Checked ? "1" : "0";
                            finance.Planning_Level          = Planning_Level.SelectedValue;
                            finance.Relevant_To_Cash        = Relevant_To_Cash.Checked ? "1" : "0";
                            finance.Yes_No                  = Yes_No.SelectedValue;
                            finance.GL_Cost_Element_Category = GL_Cost_Element_Category.SelectedValue;
                            finance.Financial_Statement     = Financial_Statement.Text;

                        }
                        #endregion

                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, finance);
                    }
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }
                    #endregion


                    #region “DMO Maintain”步骤
                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {
                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (HKF_Finance.process == TaskAPI.Process & HKF_Finance.incident == TaskAPI.Incident).Edit<HKF_Finance>(p =>
                        {
                            // p.SAP_Code = SAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;
                            
                        }
                        );
                    }

                    #endregion
                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (HKF_Finance.process == TaskAPI.Process & HKF_Finance.incident == TaskAPI.Incident).Edit<HKF_Finance>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见

                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();
                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {

                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }
                    (HKF_Finance.process == TaskAPI.Process & HKF_Finance.incident == 0 & HKF_Finance.userName == UserAPI.UserName).Edit<HKF_Finance>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.assignedToUserName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });


                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 CheckedChanged
        protected void VD_CheckedChanged(object sender, EventArgs e)
        {

            if (!VD.Checked && !SA.Checked && !SA2.Checked && !SA3.Checked && !SA4.Checked)
            {
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留一个选择项！',false)");
                VD.Checked = true;
            }
            SetVisible(false,P_VD,P_SA,P_SA2,P_SA3,P_SA4);
            switch(((Anthem.CheckBox)sender).ID)
            {
                case "VD":
                    
                    if (VD.Checked)
                    {
                        //SA.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                        VD_L.Visible = VD.Checked;
                    }
                    //VD.Checked = !(SA.Checked | SA2.Checked);

                    //VD_L.Visible = VD.Checked;
                    break;
                case "SA":
                    if (SA.Checked)
                    {
                        //VD.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                        SA_L.Visible = SA.Checked;
                    }
                    //SA_L.Visible = SA.Checked;
                    //if (!SA.Checked & !SA2.Checked) SA.Checked = true;
                    //VD.Checked = !(SA.Checked | SA2.Checked);
                    //SA_L.Visible = SA.Checked;
                    //if (!SA.Checked & SA2.Checked) { SA2_L.CssClass = "tabs1"; Tabs_Click(SA2_L, e); }
                    break;
                
                case "SA2":
                    if (SA2.Checked)
                    {
                        //VD.Checked = false;
                        //SA.Checked = false;
                        //SA3.Checked = false;
                        SA2_L.Visible = SA2.Checked;
                    }

                    //SA2_L.Visible = SA2.Checked;
                    //if (!SA.Checked & !SA2.Checked) SA2.Checked = true;
                    //VD.Checked = !(SA.Checked | SA2.Checked);
                    //SA2_L.Visible = SA2.Checked;
                    break;

                case "SA3":
                    if (SA3.Checked)
                    {
                        //VD.Checked = false;
                        //SA.Checked = false;
                        //SA2.Checked = false;
                        SA3_L.Visible = SA3.Checked;
                    }
                    //SA3_L.Visible = SA3.Checked;
                    break;

                case "SA4":
                    if (SA4.Checked)
                    {
                        //VD.Checked = false;
                        //SA.Checked = false;
                        //SA2.Checked = false;
                        SA4_L.Visible = SA4.Checked;
                    }
                    //SA3_L.Visible = SA3.Checked;
                    break;
            }
           
            InitTabs();
        }
        #endregion

        #region 事件 Actions变换
        protected void Actions_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetColor();
            SetEnable((Actions.SelectedValue == "1" || Actions.SelectedValue == "2" || Actions.SelectedValue == "3" || Actions.SelectedValue == "4"), DrpPriority, IS_Cost_Element, Vaild_From, Vaild_To, RE_Cost_Element, RE_CO_Area, Name, Description, Cost_Element_Category, Cost_Element_Group, Copy_Cost_Element_Group, Element_Group_Name, Cost_Element_1, Cost_Element_2, Cost_Element_3, Cost_Element_4, IS_Cost_Center, IS_Center_From, IS_Center_To, RE_Cost_Center, Cost_Center_CO_Area, Cost_Center_Name, Cost_Center_Description, Person_Responsible, Cost_Center_Category, Hierarchy_Area, Company_Code, Functional_Area, Currency, Profit_Center, Cost_Center_Group, Copy_Cost_Center_Group, Copy_CO_Area, Center_Group_Name, Center_Group_Name_1, Center_Group_Name_2, Center_Group_Name_3, Center_Group_Name_4, Center_Group_Name_5, IS_GL_Account, IS_1718, IS_4118, IS_4119, IS_8856, IS_4127, RE_GL_Account, RE_1718, RE_4118, RE_4119, RE_8856, RE_4127, Account_Currency, Only_Balance, Tax_Category, Without_Tax, Recon_Account, Account_No, Open_Item, Accounting_Clerk, Field_Status_Group, Post_Automatically_Only, Planning_Level, Relevant_To_Cash, Yes_No, GL_Cost_Element_Category);
            
        }
        #endregion

        #region 事件 Tabs切换
        protected void Tabs_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3, P_SA4);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            SA3_L.CssClass = "tabs1";
            SA4_L.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "VD_L":
                    VD_L.CssClass = "tabs2";
                    P_VD.Visible = true;
                    break;
                case "SA_L":
                    SA_L.CssClass = "tabs2";
                    P_SA.Visible = true;
                    break;
                case "SA2_L":
                    SA2_L.CssClass = "tabs2";
                    P_SA2.Visible = true;
                    break;
                case "SA3_L":
                    SA3_L.CssClass = "tabs2";
                    P_SA3.Visible = true;
                    break;
                case "SA4_L":
                    SA4_L.CssClass = "tabs2";
                    P_SA4.Visible = true;
                    break;
            }
            #endregion
        }
        #endregion

        #region 方法 初始化Tabs
        protected void InitTabs()
        {
            VD_L.Visible = VD.Checked;
            SA_L.Visible = SA.Checked;
            SA2_L.Visible = SA2.Checked;
            SA3_L.Visible = SA3.Checked;
            SA4_L.Visible = SA4.Checked;

            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3, P_SA4);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            SA3_L.CssClass = "tabs1";
            SA4_L.CssClass = "tabs1";

            //默认第1个显示 Tabs被选中
            if (VD_L.Visible)
            {
                VD_L.CssClass = "tabs2";
                P_VD.Visible = true;
                return;
            }

            if (SA_L.Visible)
            {
                SA_L.CssClass = "tabs2";
                P_SA.Visible = true;
                return;
            }

            if (SA2_L.Visible)
            {
                SA2_L.CssClass = "tabs2";
                P_SA2.Visible = true;
                return;
            }

            if (SA3_L.Visible)
            {
                SA3_L.CssClass = "tabs2";
                P_SA3.Visible = true;
                return;
            }

            if (SA4_L.Visible)
            {
                SA4_L.CssClass = "tabs2";
                P_SA4.Visible = true;
                return;
            }
            
        }
        #endregion

        #region 方法 SetColor
        protected void SetColor()
        {
            SetForeColor(Color.Black,Element_Group_Name_L,Financial_Statement_L, Cost_Element_Group_L,Center_Group_Name_L, Cost_Center_Group_L, IS_Cost_Center_L, IS_Center_From_L, IS_Center_To_L, Cost_Center_Name_L, Cost_Center_Description_L, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Company_Code_L,Functional_Area_L, Currency_L, Profit_Center_L, IS_Cost_Element_L, Vaild_From_L, Vaild_To_L, Name_L, Description_L, Cost_Element_Category_L, IS_GL_Account_L, IS_Company_Code_L, Account_Currency_L, Field_Status_Group_L, Yes_No_L);
            
            switch (Actions.SelectedValue)
            {
                case "1":
                    SetForeColor(Color.Blue, Element_Group_Name_L, Financial_Statement_L, Cost_Element_Group_L, Center_Group_Name_L, Cost_Center_Group_L, IS_Cost_Center_L, IS_Center_From_L, IS_Center_To_L, Cost_Center_Name_L, Cost_Center_Description_L, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Company_Code_L, Functional_Area_L, Currency_L, Profit_Center_L, IS_Cost_Element_L, Vaild_From_L, Vaild_To_L, Name_L, Description_L, Cost_Element_Category_L, IS_GL_Account_L, IS_Company_Code_L, Account_Currency_L, Field_Status_Group_L, Yes_No_L);
                    break;

                case "2":
                    SetForeColor(Color.Blue, Element_Group_Name_L, Center_Group_Name_L, Cost_Center_Name_L, Name_L, Cost_Element_Group_L, Cost_Center_Group_L, IS_Cost_Center_L, IS_Cost_Element_L, IS_GL_Account_L, IS_Company_Code_L);
                    break;

                case "3":
                    SetForeColor(Color.Blue, Element_Group_Name_L, Center_Group_Name_L, Cost_Center_Name_L, Name_L, Cost_Element_Group_L, Cost_Center_Group_L, IS_Cost_Center_L, IS_Cost_Element_L, IS_GL_Account_L, IS_Company_Code_L);
                    break;

                case "4":
                    SetForeColor(Color.Blue, Element_Group_Name_L, Center_Group_Name_L, Cost_Center_Name_L, Name_L, Cost_Element_Group_L, Cost_Center_Group_L, IS_Cost_Center_L, IS_Cost_Element_L, IS_GL_Account_L, IS_Company_Code_L);
                    break;
            }
        }
        #endregion

        #region 方法 SetDefaultValue(设置默认值, 并禁用输入)
        public void SetDefaultValue()
        {

            Element_Group_CO_Area.Text = "3000";
            Chart_Accounts.Text = "DECO";
            Center_Group_CO_Area.Text = "3000";
            IS_Center_CO_Area.Text = "3000";
            Record_Quantity.Checked = false;
            Actual_Revenues.Checked = true;
            Plan_Revenues.Checked = true;
          
            IS_CO_Area.Text = "3000";
            Line_Item.Checked = true;
            Sort_key.Text = "001,Posting date";
            
            SetEnable(false, Chart_Accounts, Element_Group_CO_Area, Center_Group_CO_Area, Plan_Revenues, Actual_Revenues, Record_Quantity, IS_Center_CO_Area, IS_CO_Area, Line_Item, Sort_key);
            SetForeColor(Color.Orange, Chart_Accounts_L, Element_Group_CO_Area_L, Center_Group_CO_Area_L, Plan_Revenues, Actual_Revenues_L, Record_Quantity_L, IS_Center_CO_Area_L, IS_CO_Area_L, Line_Item_L, Sort_key_L);
        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                Cost_Center_Category.Items.Clear();
                Cost_Center_Category.Items.Add(new ListItem("", ""));
                IList<m_Center_Category> hys = (m_Center_Category.status == 1).List<m_Center_Category>();
                foreach (m_Center_Category HY in hys)
                {
                    Cost_Center_Category.Items.Add(new ListItem(HY.Cost_Center_Category, HY.Cost_Center_Category));
                }


                Functional_Area.Items.Clear();
                Functional_Area.Items.Add(new ListItem("", ""));
                IList<m_PRC_HK_Functional_Area> ccc2 = (m_PRC_HK_Functional_Area.status == 1).List<m_PRC_HK_Functional_Area>();
                foreach (m_PRC_HK_Functional_Area HY in ccc2)
                {
                    Functional_Area.Items.Add(new ListItem(HY.Functional_Area, HY.Functional_Area));
                }
                Currency.Items.Clear();
                Currency.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Currency> ccc = (m_Cost_Center_Currency.status == 1).List<m_Cost_Center_Currency>();
                foreach (m_Cost_Center_Currency HY in ccc)
                {
                    Currency.Items.Add(new ListItem(HY.Cost_Center_Currency, HY.Cost_Center_Currency));
                }

                Profit_Center.Items.Clear();
                Profit_Center.Items.Add(new ListItem("", ""));
                IList<m_Profit_Center> mpc = (m_Profit_Center.status == 1).List<m_Profit_Center>();
                foreach (m_Profit_Center HY in mpc)
                {
                    Profit_Center.Items.Add(new ListItem(HY.Profit_Center, HY.Profit_Center));
                }
                
                Cost_Element_Category.Items.Clear();
                Cost_Element_Category.Items.Add(new ListItem("", ""));
                IList<m_Cost_Element_Category> hys1 = (m_Cost_Element_Category.status == 1).List<m_Cost_Element_Category>();
                foreach (m_Cost_Element_Category HY in hys1)
                {
                    Cost_Element_Category.Items.Add(new ListItem(HY.Cost_Element_Category, HY.Cost_Element_Category));
                }

                Account_Currency.Items.Clear();
                Account_Currency.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Currency> ccc1 = (m_Cost_Center_Currency.status == 1).List<m_Cost_Center_Currency>();
                foreach (m_Cost_Center_Currency HY in ccc1)
                {
                    Account_Currency.Items.Add(new ListItem(HY.Cost_Center_Currency, HY.Cost_Center_Currency));
                }

                Field_Status_Group.Items.Clear();
                Field_Status_Group.Items.Add(new ListItem("", ""));
                IList<m_Field_Status_Group> fsg = (m_Field_Status_Group.status == 1).List<m_Field_Status_Group>();
                foreach (m_Field_Status_Group HY in fsg)
                {
                    Field_Status_Group.Items.Add(new ListItem(HY.Field_Status_Group, HY.Field_Status_Group));
                }

                Planning_Level.Items.Clear();
                Planning_Level.Items.Add(new ListItem("", ""));
                IList<m_Planning_Level> mpl = (m_Planning_Level.status == 1).List<m_Planning_Level>();
                foreach (m_Planning_Level HY in mpl)
                {
                    Planning_Level.Items.Add(new ListItem(HY.Planning_Level, HY.Planning_Level));
                }

                GL_Cost_Element_Category.Items.Clear();
                GL_Cost_Element_Category.Items.Add(new ListItem("", ""));
                IList<m_GLAccount_Element_Category> gec = (m_GLAccount_Element_Category.status == 1).List<m_GLAccount_Element_Category>();
                foreach (m_GLAccount_Element_Category HY in gec)
                {
                    GL_Cost_Element_Category.Items.Add(new ListItem(HY.Cost_Element_Category, HY.Cost_Element_Category));
                }

                Center_Group_Name_1.Items.Clear();
                Center_Group_Name_1.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Group> gec1 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                foreach (m_Cost_Center_Group CG1 in gec1)
                {
                    Center_Group_Name_1.Items.Add(new ListItem(CG1.Cost_Center_Group, CG1.Cost_Center_Group));
                }

                Center_Group_Name_2.Items.Clear();
                Center_Group_Name_2.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Group> gec2 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                foreach (m_Cost_Center_Group CG2 in gec2)
                {
                    Center_Group_Name_2.Items.Add(new ListItem(CG2.Cost_Center_Group, CG2.Cost_Center_Group));
                }

                Center_Group_Name_3.Items.Clear();
                Center_Group_Name_3.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Group> gec3 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                foreach (m_Cost_Center_Group CG3 in gec3)
                {
                    Center_Group_Name_3.Items.Add(new ListItem(CG3.Cost_Center_Group, CG3.Cost_Center_Group));
                }

                Center_Group_Name_4.Items.Clear();
                Center_Group_Name_4.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Group> gec4 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                foreach (m_Cost_Center_Group CG4 in gec4)
                {
                    Center_Group_Name_4.Items.Add(new ListItem(CG4.Cost_Center_Group, CG4.Cost_Center_Group));
                }

                Center_Group_Name_5.Items.Clear();
                Center_Group_Name_5.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Group> gec5 = (m_Cost_Center_Group.status == 1).List<m_Cost_Center_Group>();
                foreach (m_Cost_Center_Group CG5 in gec5)
                {
                    Center_Group_Name_5.Items.Add(new ListItem(CG5.Cost_Center_Group, CG5.Cost_Center_Group));
                }

                Cost_Element_1.Items.Clear();
                Cost_Element_1.Items.Add(new ListItem("", ""));
                IList<m_HK_Cost_Element> hce1 = (m_HK_Cost_Element.status == 1).List<m_HK_Cost_Element>();
                foreach (m_HK_Cost_Element HC in hce1)
                {
                    Cost_Element_1.Items.Add(new ListItem(HC.Cost_Element, HC.Cost_Element));
                }

                Cost_Element_2.Items.Clear();
                Cost_Element_2.Items.Add(new ListItem("", ""));
                IList<m_HK_Cost_Element> hce2 = (m_HK_Cost_Element.status == 1).List<m_HK_Cost_Element>();
                foreach (m_HK_Cost_Element HC in hce2)
                {
                    Cost_Element_2.Items.Add(new ListItem(HC.Cost_Element, HC.Cost_Element));
                }

                Cost_Element_3.Items.Clear();
                Cost_Element_3.Items.Add(new ListItem("", ""));
                IList<m_HK_Cost_Element> hce3 = (m_HK_Cost_Element.status == 1).List<m_HK_Cost_Element>();
                foreach (m_HK_Cost_Element HC in hce3)
                {
                    Cost_Element_3.Items.Add(new ListItem(HC.Cost_Element, HC.Cost_Element));
                }

                Cost_Element_4.Items.Clear();
                Cost_Element_4.Items.Add(new ListItem("", ""));
                IList<m_HK_Cost_Element> hce4 = (m_HK_Cost_Element.status == 1).List<m_HK_Cost_Element>();
                foreach (m_HK_Cost_Element HC in hce4)
                {
                    Cost_Element_4.Items.Add(new ListItem(HC.Cost_Element, HC.Cost_Element));
                }

                Copy_Cost_Center_Group.Items.Clear();
                Copy_Cost_Center_Group.Items.Add(new ListItem("", ""));
                IList<m_Cost_Center_Group_2> ccg2 = (m_Cost_Center_Group_2.status == 1).List<m_Cost_Center_Group_2>();
                foreach (m_Cost_Center_Group_2 HC in ccg2)
                {
                    Copy_Cost_Center_Group.Items.Add(new ListItem(HC.Cost_Center_Group_2, HC.Cost_Center_Group_2));
                }



                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {
            List<string> vald_s = new List<string>();
            List<string> vald_s_2 = new List<string>();
            List<string> vald_s_3 = new List<string>();
            List<string> vald_s_4 = new List<string>();
            List<string> vald_s_5 = new List<string>();
            List<string> vald_s_6= new List<string>();
            List<Regular> regs = new List<Regular>();
            
            
            
            #region VD
            if (VD.Checked && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Cost_Element.Text, "Cost Element 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Vaild_From.Text, "Vaild From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Vaild_To.Text, "Vaild To 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Name.Text, "Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Description.Text, "Description 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Element_Category.SelectedValue, "Cost Element Category 必填"));
            }

            if (VD.Checked && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Cost_Element.Text, "Cost Element 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Name.Text, "Name 必填"));
            }

            vald_s = Validation(regs);
            if (vald_s.Count > 0)
            {
                vald_s.Insert(0, "<font color='#0000FF'><b>Cost Element</b></font>");
            }
            #endregion

            #region SA
            regs.Clear();
            if (SA.Checked && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Element_Group.Text, "Cost Element Group   必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Element_Group_Name.Text, "Name   必填"));

            }

            if (SA.Checked && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Element_Group.Text, "Cost Element Group   必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Element_Group_Name.Text, "Name   必填"));
            }

            vald_s_2 = Validation(regs);
            if (vald_s_2.Count > 0)
            {
                vald_s_2.Insert(0, "<font color='#0000FF'><b>Cost Element Group</b></font>");
                vald_s.AddRange(vald_s_2);
            }

            #endregion
          

            #region SA2
            regs.Clear();
            if (SA2.Checked && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Cost_Center.Text, "Cost center 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Center_From.Text, "Vaild From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Center_To.Text, "Vaild To 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Name.Text, "Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Description.Text, "Description 必填"));
                
                if (RE_Cost_Center.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, Person_Responsible.Text, "Person Responsible 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Category.SelectedValue, "Cost Center Category 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Hierarchy_Area.Text, "Hierarchy Area 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Company_Code.SelectedValue, "Company Code 必填"));

                    regs.Add(new Regular(RegularExp.NotEmpty, Functional_Area.SelectedValue, "Functional Area 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Currency.SelectedValue, "Currency 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, Profit_Center.SelectedValue, "Profit Center 必填"));
                }
            }

            if (SA2.Checked && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_Cost_Center.Text, "Initial Screen: Cost center 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Name.Text, "Name 必填"));
            }

            vald_s_3 = Validation(regs);
            if (vald_s_3.Count > 0)
            {
                vald_s_3.Insert(0, "<font color='#0000FF'><b>Cost Center</b></font>");
                vald_s.AddRange(vald_s_3);
            }
            #endregion

            #region SA3
            regs.Clear();
            if (SA3.Checked && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Group.Text, " Cost Center Group 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Center_Group_Name.Text, "Center_Group_Name 必填"));
            }

            if (SA3.Checked && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Cost_Center_Group.Text, "Cost Center Group 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Center_Group_Name.Text, "Name 必填"));
            }

            vald_s_4 = Validation(regs);
            if (vald_s_4.Count > 0)
            {
                vald_s_4.Insert(0, "<font color='#0000FF'><b>Cost Center Group</b></font>");
                vald_s.AddRange(vald_s_4);
            }
            #endregion

            #region SA4
            regs.Clear();
            if (SA4.Checked && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_GL_Account.Text, "GL Accountt 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, (!IS_1718.Checked && !IS_4118.Checked && !IS_4119.Checked && !IS_8856.Checked && !IS_4127.Checked ? "" : "NotBlank"), "Company Code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Account_Currency.SelectedValue, "Account Currency 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Field_Status_Group.SelectedValue, "Field Status Group 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Yes_No.SelectedValue, "Yes / No 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Financial_Statement.Text, "Financial statement version node (CN00) 必填"));
                if (Yes_No.SelectedValue == "Yes")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty,GL_Cost_Element_Category.SelectedValue, "Cost Element Category 必填"));
                }

            }

            if (SA4.Checked && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, IS_GL_Account.Text, "GL Accountt 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, (!IS_1718.Checked && !IS_4118.Checked && !IS_4119.Checked && !IS_8856.Checked && !IS_4127.Checked ? "" : "NotBlank"), "Company Code 必填"));

            }

            vald_s_5 = Validation(regs);
            if (vald_s_5.Count > 0)
            {
                vald_s_5.Insert(0, "<font color='#0000FF'><b>GL Account</b></font>");
                vald_s.AddRange(vald_s_5);
            }

            
            #endregion
        
            return vald_s;
            //return Validation(regs);
        }
        #endregion

        #region 方法 Others
        private string getFormCheckList(Anthem .CheckBoxList ck)
        {
            string t = "";
            for (int i = 0; i < ck.Items.Count; i++)
                if (ck.Items[i].Selected)
                    t += "," + ck.Items[i].Value;
                else
                    t += ",";
            return t;
        }
        private Anthem.CheckBoxList setCheckList(string t, Anthem .CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion

        #region 事件Yes/No
        protected void Yes_No_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && Yes_No.Text == "Yes")
            {
                SetForeColor(Color.Blue, GL_Cost_Element_Category_L);
            }
            else
            {
                SetForeColor(Color.Black, GL_Cost_Element_Category_L);
            }
        }
        #endregion

        #region 方法 SetDropDownListValue
        private void SetDropDownListValue(Anthem.DropDownList drpT, object o)
        {
            try
            {
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) || drpT.Items.FindByValue(o.ToString()) != null)
                {
                    drpT.SelectedValue = o.ToString();
                    return;
                }

                drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                drpT.SelectedIndex = 0;

            }
            catch (Exception)
            {
            }
        }
        #endregion

        #region 重载 OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsLoaded && TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            {
                Actions_SelectedIndexChanged(null, e);
            }

            base.OnLoadComplete(e);
        }
        #endregion      

        #region 事件Cost Center
        protected void RE_Cost_Center_TextChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1")
            {
                if (RE_Cost_Center.Text != "")
                {
                    SetForeColor(Color.Black, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Company_Code_L, Functional_Area_L, Currency_L, Profit_Center_L);
                }
                else
                {
                    SetForeColor(Color.Blue, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Company_Code_L, Functional_Area_L, Currency_L, Profit_Center_L);
                }
            }
            else
            {
                SetForeColor(Color.Black, Person_Responsible_L, Cost_Center_Category_L, Hierarchy_Area_L, Company_Code_L, Functional_Area_L, Currency_L, Profit_Center_L);
            }
        }
        #endregion


    }
}